package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Approve.ApproveDetail_Activity;
import cn.com.infohold.smartcity.api.bean.ApproveBean;
import cn.com.infohold.smartcity.api.bean.WarrantBean;
import cn.com.infohold.smartcity.parent.ParentActivity;
import library.utils.Utils;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class Approve_Adapter extends RecyclerView.Adapter<Approve_Adapter.mViewHolder>{

    private Context context;
    private List<WarrantBean> mList;
    private boolean isApprove;

    public Approve_Adapter(Context context, List<WarrantBean> mList, boolean isApprove) {
        this.context = context;
        this.mList = mList;
        this.isApprove = isApprove;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_approve, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {

        WarrantBean bean = mList.get(position);

        switch (bean.getStatus()){
            case 1:
                holder.tv_status.setText("保存");
                break;
            case 2:
                holder.tv_status.setText("提交一级审批");
                break;
            case 3:
                holder.tv_status.setText("一级审批未通过");
                break;
            case 4:
                holder.tv_status.setText("一级审批关闭");
                break;
            case 5:
                holder.tv_status.setText("待二级审批");
                break;
            case 6:
                holder.tv_status.setText("二级审批不通过");
                break;
            case 7:
                holder.tv_status.setText("二级审批关闭");
                break;
            case 8:
                holder.tv_status.setText("二级审批通过");
                break;
            default:
                break;
        }
        holder.tv_certificatedate.setText(bean.getCertificatedate());
        holder.tv_contractingpartyname.setText(bean.getContractingpartyname());
        holder.tv_remark.setText(bean.getRemark());

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,ApproveDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("approve_detail",bean);
                bundle.putBoolean("isApprove",isApprove);
                intent.putExtra("approve_detail",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder{
        LinearLayout ll_item;
        TextView tv_status;
        TextView tv_certificatedate;
        TextView tv_contractingpartyname;
        TextView tv_address;
        TextView tv_remark;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_status = (TextView) itemView.findViewById(R.id.tv_status);
            tv_certificatedate = (TextView) itemView.findViewById(R.id.tv_certificatedate);
            tv_contractingpartyname = (TextView) itemView.findViewById(R.id.tv_contractingpartyname);
            tv_address = (TextView) itemView.findViewById(R.id.tv_address);
            tv_remark = (TextView) itemView.findViewById(R.id.tv_remark);
        }
    }
}
